package com.cloud.pole.advert.biz;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.cloud.pole.advert.model.entity.Advert;
import com.cloud.pole.common.biz.BaseBiz;
import com.cloud.pole.mapper.AdvertMapper;

/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-08 16:23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AdvertBiz extends BaseBiz<AdvertMapper, Advert> {

	@Cache(key = "advert{1}")
	public List<Advert> selectListByAdvertPosId(Integer id) {
		Advert advert = new Advert();
		advert.setAdvertPosId(id);
		advert.setAdvertStatus(Advert.ADVERT_STATUS_OK);
		return selectList(advert);
	}

	@Cache(key="advert{1}shopId{2}posId")
    public List<Advert> selectListByShopId(Integer shopId, Integer posId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("shopId", shopId);
		map.put("posId", posId);
        return mapper.selectListByShopId(map);
    }

	@CacheClear(key="advert{1}shopId{2}posId")
	public void deleteByShopId(Integer shopId, Integer posId){
		Advert record = new Advert();
		record.setShopId(shopId);
		record.setAdvertPosId(posId);
		mapper.delete(record);
	}
	
	@CacheClear(key="advert{1.shopId}shopId{1.advertPosId}posId")
	public void insertSelectiveByShopId(Advert record) {
		mapper.insertSelective(record);
	}
	
	public List<Advert> selectByPage(Integer shopId) {
		return mapper.selectPageAll(shopId);
	}

	@CacheClear(keys= {"advert{1.shopId}","advert{1.shopId}shopId{1.advertPosId}posId"})
	public void addOpendBanner(Advert advert) {
		mapper.inserBanner(advert);
	}
	
	public Advert selectByAdvertId(Integer AdvertId) {
	     return	mapper.selectByAdvertId(AdvertId);
	}
	@CacheClear(keys= {"advert{1.shopId}","advert{1.shopId}shopId{1.advertPosId}posId"})
	public void updateOpendBanner(Advert advert) {
		mapper.updateEndBanner(advert);
	}
	@CacheClear(keys= {"advert{1.shopId}","advert{1.shopId}shopId{1.advertPosId}posId"})
	public void deleteBanner(Integer advertId) {
		mapper.deleteOpendBanner(advertId);
	}
}
